package gui.mainFrame;

import gui.GUIController;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import testGenerator.Controller;

/**
 * Provides buttons for main GUI.
 * @author William Whitney
 */
public class TestConditionBtnPanel extends JPanel
{
    private static final long serialVersionUID = 1L;

    private GUIController guiController;
    private final Controller control;
    private JButton previousMethodBtn;
    private JButton nextMethodButton;
    private JButton exportTests;
    private JLabel actualPathLabel;

    /**
     * Default constructor.
     * @param control
     * @param guiControl  
     */
    public TestConditionBtnPanel(Controller control, GUIController guiControl)
    {
        //Save controller
        this.guiController = guiControl;

        //Save controller
        this.control = control;

        //Setup Panel properties
        this.setupPanelProperties();

        //Add Label with path of source code
        this.addPathLabel();
        
        //Add Buttons
        this.addButtons();
    }

    /**
     * Adds Label to the panel with path of source code
     */
    private void addPathLabel() {
        String actualPath = control.getSourceLoc();
        if ("".equals(actualPath)) {
            actualPath = "No file selected yet.";
        }
        //Path of actual source code Label
        actualPathLabel = new JLabel("Currently working on: " + actualPath);
        this.add(actualPathLabel);
    }
    /**
     * Adds buttons to the panel.
     */
    private void addButtons()
    {
        //Previous Method Button
        previousMethodBtn = new JButton("Previous Method");
        previousMethodBtn.addActionListener(getPreviousMethodBtnAction());
        this.add(previousMethodBtn);

        //Next Method Button
        nextMethodButton = new JButton("Next Method");
        nextMethodButton.addActionListener(getNextMethodButtonAction());
        this.add(nextMethodButton);

        //Export Test Button
        exportTests = new JButton("Export Tests");
        exportTests.addActionListener(getExportTestBtnListener());
        this.add(exportTests);

    }

    /**
     * This setup panel properties.
     */
    private void setupPanelProperties()
    {
        FlowLayout layout = new FlowLayout();
        layout.setAlignment(SwingConstants.RIGHT);
        this.setLayout(layout);
    }

   

    private ActionListener getPreviousMethodBtnAction()
    {
        return new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                guiController.prevMethod();
            }
        };
    }

    private ActionListener getNextMethodButtonAction()
    {
        return new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                guiController.nextMethod();
            }
        };
    }

    private ActionListener getExportTestBtnListener()
    {
        return new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                guiController.showTestViewer();
            }
        };
    }

    public void disableBtns(boolean val)
    {
        this.exportTests.setEnabled(!val);
        this.nextMethodButton.setEnabled(!val);
        this.previousMethodBtn.setEnabled(!val);
    }
}
